Imports System
Imports System.Drawing
Imports System.Collections.Generic
Imports System.Collections
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Runtime.Serialization
Imports System.Globalization
Imports System.Text.RegularExpressions
Imports System.ComponentModel

Namespace C4F.DevKit.PowerManagement
#Region "Structures"
    ''' <summary>
    ''' Represents the status of the battery.
    ''' </summary>
    Public Structure BatteryStatus
#Region "Private Members"
        ''' <summary>
        ''' If true, at least one battery is present in the system.
        ''' </summary>
        Private m_batteryPresent As Boolean
        ''' <summary>
        ''' If this member is TRUE, a battery is currently charging. 
        ''' </summary>
        Private m_charging As Boolean
        ''' <summary>
        ''' The battery charge status.
        ''' </summary>
        Private m_batteryFlag As BatteryFlag
        ''' <summary>
        ''' The percentage of full battery charge remaining. 
        ''' This member can be a value in the range 0 to 100, 
        ''' or 255 if status is unknown.
        ''' </summary>
        Private m_batteryLifePercent As Byte
#End Region
#Region "Properties"
        ''' <summary>
        ''' If true, at least one battery is present in the system.
        ''' </summary>
        Public Property BatteryPresent() As Boolean
            Get
                Return m_batteryPresent
            End Get
            Set(ByVal value As Boolean)
                m_batteryPresent = value
            End Set
        End Property
        ''' <summary>
        ''' If this member is TRUE, a battery is currently charging. 
        ''' </summary>
        Public Property Charging() As Boolean
            Get
                Return m_charging
            End Get
            Set(ByVal value As Boolean)
                m_charging = value
            End Set
        End Property
        ''' <summary>
        ''' The battery charge status.
        ''' </summary>
        Public Property BatteryFlag() As BatteryFlag
            Get
                Return m_batteryFlag
            End Get
            Set(ByVal value As BatteryFlag)
                m_batteryFlag = value
            End Set
        End Property
        ''' <summary>
        ''' The percentage of full battery charge remaining. 
        ''' This member can be a value in the range 0 to 100, 
        ''' or 255 if status is unknown.
        ''' </summary>
        Public Property BatteryLifePercent() As Byte
            Get
                Return m_batteryLifePercent
            End Get
            Set(ByVal value As Byte)
                m_batteryLifePercent = value
            End Set
        End Property
#End Region
    End Structure
    ''' <summary>
    ''' Represents System battery status.
    ''' </summary>
    Public Structure SystemBatteryState
#Region "Private Members"
        ''' <summary>
        ''' If this member is TRUE, the system battery charger is currently 
        ''' operating on external power. 
        ''' </summary>
        Private m_alternateCurrentOnline As Boolean
        ''' <summary>
        ''' If this member is TRUE, at least one battery is present in the 
        ''' system. 
        ''' </summary>
        Private m_batteryPresent As Boolean
        ''' <summary>
        ''' If this member is TRUE, a battery is currently charging. 
        ''' </summary>
        Private m_charging As Boolean
        ''' <summary>
        ''' If this member is TRUE, a battery is currently discharging. 
        ''' </summary>
        Private m_discharging As Boolean
        ''' <summary>
        ''' Reserved. 
        ''' </summary>
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> _
        Private m_spare As Byte()
        ''' <summary>
        ''' The theoretical capacity of the battery when new, in mWh.
        ''' </summary>
        Private m_maxCapacity As UInt32
        ''' <summary>
        ''' The estimated remaining capacity of the battery, in mWh.
        ''' </summary>
        Private m_remainingCapacity As UInt32
        ''' <summary>
        ''' The current rate of discharge of the battery, in mW. 
        ''' A nonzero, positive rate indicates charging; 
        ''' a negative rate indicates discharging. 
        ''' </summary>
        Private m_rate As UInt32
        ''' <summary>
        ''' The estimated time remaining on the battery, in seconds. 
        ''' </summary>
        Private m_estimatedTime As UInt32
        ''' <summary>
        ''' The manufacturer's suggestion of a capacity, in mWh,
        ''' at which a low battery alert should occur.
        ''' </summary>
        Private m_defaultAlert1 As UInt32
        ''' <summary>
        ''' The manufacturer's suggestion of a capacity, in mWh,
        ''' at which a warning battery alert should occur.
        ''' </summary>
        Private m_defaultAlert2 As UInt32
#End Region
#Region "Properties"
        ''' <summary>
        ''' If this member is TRUE, the system battery charger is currently 
        ''' operating on external power. 
        ''' </summary>
        Public Property AlternateCurrentOnline() As Boolean
            Get
                Return m_alternateCurrentOnline
            End Get
            Set(ByVal value As Boolean)
                m_alternateCurrentOnline = value
            End Set
        End Property
        ''' <summary>
        ''' If this member is TRUE, at least one battery is present in the 
        ''' system. 
        ''' </summary>
        Public Property BatteryPresent() As Boolean
            Get
                Return m_batteryPresent
            End Get
            Set(ByVal value As Boolean)
                m_batteryPresent = value
            End Set
        End Property
        ''' <summary>
        ''' If this member is TRUE, a battery is currently charging. 
        ''' </summary>
        Public Property Charging() As Boolean
            Get
                Return m_charging
            End Get
            Set(ByVal value As Boolean)
                m_charging = value
            End Set
        End Property
        ''' <summary>
        ''' If this member is TRUE, a battery is currently discharging. 
        ''' </summary>
        Public Property Discharging() As Boolean
            Get
                Return m_discharging
            End Get
            Set(ByVal value As Boolean)
                m_discharging = value
            End Set
        End Property
        ''' <summary>
        ''' Reserved. 
        ''' </summary>
        Public ReadOnly Property Spare() As ArrayList
            Get
                Dim spareArrayList As ArrayList = New ArrayList()
                For index As Integer = 0 To m_spare.Length - 1
                    spareArrayList.Add(m_spare(index))
                Next
                Return spareArrayList
            End Get
        End Property
        ''' <summary>
        ''' The theoretical capacity of the battery when new, in mWh.
        ''' </summary>
        Public Property MaxCapacity() As UInt32
            Get
                Return m_maxCapacity
            End Get
            Set(ByVal value As UInt32)
                m_maxCapacity = value
            End Set
        End Property
        ''' <summary>
        ''' The estimated remaining capacity of the battery, in mWh.
        ''' </summary>
        Public Property RemainingCapacity() As UInt32
            Get
                Return m_remainingCapacity
            End Get
            Set(ByVal value As UInt32)
                m_remainingCapacity = value
            End Set
        End Property
        ''' <summary>
        ''' The current rate of discharge of the battery, in mW. 
        ''' A nonzero, positive rate indicates charging; 
        ''' a negative rate indicates discharging. 
        ''' </summary>
        Public Property Rate() As UInt32
            Get
                Return m_rate
            End Get
            Set(ByVal value As UInt32)
                m_rate = value
            End Set
        End Property
        ''' <summary>
        ''' The estimated time remaining on the battery, in seconds. 
        ''' </summary>
        Public Property EstimatedTime() As UInt32
            Get
                Return m_estimatedTime
            End Get
            Set(ByVal value As UInt32)
                m_estimatedTime = value
            End Set
        End Property
        ''' <summary>
        ''' The manufacturer's suggestion of a capacity, in mWh,
        ''' at which a low battery alert should occur.
        ''' </summary>
        Public Property DefaultAlert1() As UInt32
            Get
                Return m_defaultAlert1
            End Get
            Set(ByVal value As UInt32)
                m_defaultAlert1 = value
            End Set
        End Property
        ''' <summary>
        ''' The manufacturer's suggestion of a capacity, in mWh,
        ''' at which a warning battery alert should occur.
        ''' </summary>
        Public Property DefaultAlert2() As UInt32
            Get
                Return m_defaultAlert2
            End Get
            Set(ByVal value As UInt32)
                m_defaultAlert2 = value
            End Set
        End Property
#End Region
    End Structure
#End Region
#Region "Enumerations"
    ''' <summary>
    ''' Represents the battery charge status.
    ''' </summary>
    <Flags()> _
    Public Enum BatteryFlag As Byte
        ''' <summary>
        ''' The battery is not being charged and 
        ''' the battery capacity is between low and high(between 33 to 66 %).
        ''' </summary>
        BetweenLowAndHigh = 0
        ''' <summary>
        ''' The battery capacity is at more than 66 percent.
        ''' </summary>
        High = 1
        ''' <summary>
        ''' The battery capacity is at less than 33 percent.
        ''' </summary>
        Low = 2
        ''' <summary>
        ''' The battery capacity is at less than five percent.
        ''' </summary>
        Critical = 4
        ''' <summary>
        ''' Charging.
        ''' </summary>
        Charging = 8
        ''' <summary>
        ''' No system battery available.
        ''' </summary>
        NoSystemBattery = 128
        ''' <summary>
        ''' Unable to read the battery flag information.
        ''' </summary>
        UnknownStatus = 255
    End Enum
    ''' <summary>
    '''  Represents power information to be set or retrieved.
    ''' </summary>
    Public Enum PowerInformationLevel
        ''' <summary>
        ''' For No Information.
        ''' </summary>
        None = 0
        ''' <summary>
        ''' Information of System Battery State.
        ''' </summary>
        SystemBatteryState = 5
    End Enum
#End Region
#Region "PowerManager class"
    ''' <summary>
    ''' Provides wrapper over power management native APIs.
    ''' </summary>     
    <ToolboxItem(True), ToolboxBitmap(GetType(PowerManager))> _
    Public Class PowerManager
        Inherits Component
#Region "Public Properties"
        ''' <summary>
        ''' Determines whether the computer supports hibernation.
        ''' </summary>
        ''' <returns>If the computer supports hibernation (power state S4) 
        ''' and the file Hiberfil.sys is present on the system, 
        ''' the function returns TRUE.Otherwise, the function returns FALSE.
        ''' </returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public ReadOnly Property IsPowerHibernateAllowed() As Boolean
            Get
                Try
                    Return Not (PowerManagementNativeMethods.IsPowerHibernateAllowed())
                Catch exception As Exception
                    Throw New PowerManagerException(exception.Message, exception)
                End Try
            End Get
        End Property
        ''' <summary>
        ''' Determines whether the computer supports the sleep states.
        ''' </summary>
        ''' <returns>
        ''' If the computer supports the sleep states (S1, S2, and S3), 
        ''' the function returns TRUE. Otherwise, the function returns FALSE.
        ''' </returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public ReadOnly Property IsPowerSuspendAllowed() As Boolean
            Get
                Try
                    Return PowerManagementNativeMethods.IsPowerSuspendAllowed()
                Catch exception As Exception
                    Throw New PowerManagerException(exception.Message, exception)
                End Try
            End Get
        End Property
        ''' <summary>
        ''' Determines whether the computer supports the soft off power state.
        ''' </summary>
        ''' <returns>If the computer supports soft off (power state S5), 
        ''' the function returns TRUE. 
        ''' Otherwise, the function returns FALSE.</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public ReadOnly Property IsPowerShutdownAllowed() As Boolean
            Get
                Try
                    Return PowerManagementNativeMethods.IsPowerShutdownAllowed()
                Catch exception As Exception
                    Throw New PowerManagerException(exception.Message, exception)
                End Try
            End Get
        End Property
        ''' <summary>
        ''' Determines the current state of the computer.
        ''' </summary>
        ''' <returns>
        ''' If the system was restored to the working state automatically 
        ''' and the user is not active, the function returns TRUE. 
        ''' Otherwise, the function returns FALSE.
        ''' </returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public ReadOnly Property IsSystemResumeAutomatic() As Boolean
            Get
                Try
                    Return PowerManagementNativeMethods.IsSystemResumeAutomatic()
                Catch exception As Exception
                    Throw New PowerManagerException(exception.Message, exception)
                End Try
            End Get
        End Property
#End Region
#Region "Public Methods"
#Region "Power Scheme Related Methods"
        ''' <summary>
        ''' Retrieves the title of the active power scheme.
        ''' </summary>
        ''' <returns>Title of the active power scheme 
        ''' if the method succeeds else returns null.</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function GetActivePowerScheme() As String
            Try
                'Get the active power scheme guid.
                Dim schemeGuid As String = PowerManager.GetActivePowerSchemeGuid()
                'Get all available power scheme names and guids.
                Dim allSchemes As ArrayList = PowerManager.GetAvailablePowerSchemesAndGuid()
                For index As Integer = 0 To allSchemes.Count - 1
                    'Compare the active power scheme guid with retrieved
                    'power schemes' guids and get the name of active power 
                    'scheme and return it.
                    If (DirectCast(allSchemes(index), ArrayList))(0).ToString() = schemeGuid Then
                        Return (DirectCast(allSchemes(index), ArrayList))(1).ToString()
                    End If
                Next
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            Return [String].Empty
        End Function
        ''' <summary>
        ''' Sets the active power scheme.
        ''' </summary>
        ''' <param name="powerSchemeTitle">The title of the power 
        ''' scheme to be activated.</param>
        ''' <returns>True, if the method succeeds.</returns>
        ''' <exception cref="ArgumentNullException">
        ''' The required parameter is null or empty.
        ''' </exception>
        ''' <exception cref="ArgumentException">
        ''' The specified parameter is not valid.
        ''' </exception>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function SetActivePowerScheme(ByVal powerSchemeTitle As String) As Boolean
            If [String].IsNullOrEmpty(powerSchemeTitle) Then
                Throw New ArgumentNullException(PowerManagementResource.ArgumentNullMessage)
            End If
            Dim setActivePowerSchemeStatus As Boolean = False
            Dim powerSchemeExist As Boolean = False
            Try
                'Get all available power scheme names and guids.
                Dim allSchemes As ArrayList = PowerManager.GetAvailablePowerSchemesAndGuid()
                For index As Integer = 0 To allSchemes.Count - 1
                    'Get the guid of the schemename passed, pass it as parameter
                    'to SetActivePowerSchemeGuid function.
                    If (DirectCast(allSchemes(index), ArrayList))(1).ToString() = powerSchemeTitle Then
                        powerSchemeExist = True
                        setActivePowerSchemeStatus = PowerManager.SetActivePowerSchemeGuid((DirectCast(allSchemes(index), ArrayList))(0).ToString())
                        Exit For
                    End If
                Next
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not powerSchemeExist Then
                Throw New ArgumentException(PowerManagementResource.PowerSchemeNotFound)
            End If
            Return setActivePowerSchemeStatus
        End Function
        ''' <summary>
        ''' Retrieves all available power schemes.
        ''' </summary>
        ''' <returns>List of all the available power schemes.
        ''' </returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function GetAvailablePowerSchemes() As List(Of String)
            Dim allPowerSchemes As List(Of String) = New List(Of String)()
            Dim ptrToPowerScheme As IntPtr = IntPtr.Zero
            Dim friendlyName As IntPtr = IntPtr.Zero
            Try
                Dim buffSize As UInteger = 100
                Dim schemeIndex As UInteger = 0
                ptrToPowerScheme = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                'Get the guids of all available power schemes.
                While PowerManagementNativeMethods.PowerEnumerate(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, PowerManagementNativeMethods.PowerDataAccessor.AccessScheme, schemeIndex, ptrToPowerScheme, _
                 buffSize) = 0
                    friendlyName = Marshal.AllocHGlobal(1000)
                    buffSize = 1000
                    'Pass the guid retrieved in PowerEnumerate as 
                    'parameter to get the power scheme name.
                    PowerManagementNativeMethods.PowerReadFriendlyName(IntPtr.Zero, ptrToPowerScheme, IntPtr.Zero, IntPtr.Zero, friendlyName, buffSize)
                    Dim name As String = Marshal.PtrToStringUni(friendlyName)
                    'Add retrieved power scheme name in the list.
                    allPowerSchemes.Add(name)
                    schemeIndex += CType(1, UInteger)

                End While
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            Finally
                Marshal.FreeHGlobal(ptrToPowerScheme)
                Marshal.FreeHGlobal(friendlyName)
            End Try
            Return allPowerSchemes
        End Function
        ''' <summary>
        ''' Deletes the specified power scheme.
        ''' </summary>
        ''' <param name="powerSchemeTitle">The title of the power scheme to 
        ''' be deleted.</param>
        ''' <returns>True, if the method succeeds.</returns>
        ''' <exception cref="ArgumentNullException">
        ''' The required parameter is null or empty.
        ''' </exception>
        ''' <exception cref="ArgumentException">
        ''' The specified parameter is not valid.
        ''' </exception>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function DeletePowerScheme(ByVal powerSchemeTitle As String) As Boolean
            If [String].IsNullOrEmpty(powerSchemeTitle) Then
                Throw New ArgumentNullException(PowerManagementResource.ArgumentNullMessage)
            End If
            'Check whether passed powerSchemeTitle is either one of 
            'default power schemes or active power scheme.
            If powerSchemeTitle.Equals(PowerManagementResource.PowerSchemeBalancedTitle) OrElse powerSchemeTitle.Equals(PowerManagementResource.PowerSchemePowerSaverTitle) OrElse powerSchemeTitle.Equals(PowerManagementResource.PowerSchemeHighPerformanceTitle) OrElse powerSchemeTitle.Equals(Me.GetActivePowerScheme()) Then
                Throw New PowerManagerException(PowerManagementResource.DeleteSchemeMessage)
            End If
            Dim deletePowerSchemeStatus As Boolean = False
            Dim powerSchemeExist As Boolean = False
            Dim ptrToActiveScheme As IntPtr = IntPtr.Zero
            Try
                'Get all available power scheme names and guids.
                Dim allSchemes As ArrayList = PowerManager.GetAvailablePowerSchemesAndGuid()
                Dim deleteSchemeGuid As Guid = Guid.Empty
                For index As Integer = 0 To allSchemes.Count - 1
                    'Compare the active scheme names with passed scheme name
                    'and get the guid of power scheme to be deleted.
                    If (DirectCast(allSchemes(index), ArrayList))(1).ToString() = powerSchemeTitle Then
                        deleteSchemeGuid = New Guid((DirectCast(allSchemes(index), ArrayList))(0).ToString())
                        powerSchemeExist = True
                        Exit For
                    End If
                Next
                If deleteSchemeGuid <> Guid.Empty Then
                    ptrToActiveScheme = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                    Marshal.StructureToPtr(deleteSchemeGuid, ptrToActiveScheme, True)
                    'Delete the power scheme, giving powerscheme guid ad argument.
                    deletePowerSchemeStatus = Not (PowerManagementNativeMethods.PowerDeleteScheme(IntPtr.Zero, ptrToActiveScheme))
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            Finally
                Marshal.FreeHGlobal(ptrToActiveScheme)
            End Try
            'Throw exception if specified power scheme does not exist.
            If Not powerSchemeExist Then
                Throw New ArgumentException(PowerManagementResource.PowerSchemeNotFound)
            End If
            Return deletePowerSchemeStatus
        End Function
        ''' <summary>
        ''' This method retrieves the AC power setting values for the specified power scheme.
        ''' </summary>
        ''' <param name="powerSchemeTitle">The title of the power scheme.</param>
        ''' <returns>The AC power setting values for the specified power scheme.</returns>
        ''' <exception cref="ArgumentNullException">
        ''' The required parameter is null or empty.
        ''' </exception>
        ''' <exception cref="ArgumentException">
        ''' The specified parameter is not valid.
        ''' </exception>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function ReadPowerSchemeACValue(ByVal powerSchemeTitle As String) As PowerScheme
            Return PowerManager.ReadPowerSchemeValue(powerSchemeTitle, ValueType.AC)
        End Function
        ''' <summary>
        ''' This method retrieves the DC power setting values for the specified power scheme.
        ''' </summary>
        ''' <param name="powerSchemeTitle">The title of the power scheme.</param>
        ''' <returns>The DC power setting values for the specified power scheme.</returns>
        ''' <exception cref="ArgumentNullException">
        ''' The required parameter is null or empty.
        ''' </exception>
        ''' <exception cref="ArgumentException">
        ''' The specified parameter is not valid.
        ''' </exception>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function ReadPowerSchemeDCValue(ByVal powerSchemeTitle As String) As PowerScheme
            Return PowerManager.ReadPowerSchemeValue(powerSchemeTitle, ValueType.DC)
        End Function
#End Region
#Region "Battery Related Methods"
        ''' <summary>
        ''' Gets the status of battery.
        ''' </summary>
        ''' <returns>Battery status.</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function GetBatteryStatus() As BatteryStatus
            Dim systemPowerStatus As Boolean = False
            Dim batteryStatus As BatteryStatus = New BatteryStatus()
            Try
                Dim powerStatus As SystemPowerStatus = New SystemPowerStatus()
                'Get BatteryLifePercent and BatteryFlag values
                systemPowerStatus = (PowerManagementNativeMethods.GetSystemPowerStatus(powerStatus))
                batteryStatus.BatteryLifePercent = powerStatus.BatteryLifePercent
                batteryStatus.BatteryFlag = DirectCast(powerStatus.BatteryFlag, BatteryFlag)
                If (powerStatus.BatteryFlag And DirectCast(BatteryFlag.Charging, Byte)) = DirectCast(BatteryFlag.Charging, Byte) Then
                    batteryStatus.Charging = True
                Else
                    batteryStatus.Charging = False
                End If
                If (powerStatus.BatteryFlag And DirectCast(BatteryFlag.NoSystemBattery, Byte)) = DirectCast(BatteryFlag.NoSystemBattery, Byte) Then
                    batteryStatus.BatteryPresent = False
                Else
                    batteryStatus.BatteryPresent = True
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not systemPowerStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                                                       + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return batteryStatus
        End Function
#End Region
#Region "Windows Security Related Methods"
#Region "Reboot"
        ''' <summary>
        ''' Shuts down the system and then restarts the system.
        ''' </summary>
        ''' <param name="force">If True, then it forces processes to terminate.
        ''' If false then sends message to processes and it forces processes 
        ''' to terminate if they do not respond to the message within 
        ''' the timeout interval.</param>
        ''' <returns>True, if reboot has been initiated.</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function RebootComputer(ByVal force As Boolean) As Boolean
            Dim rebootComputerStatus As Boolean = False
            Dim hasPrivilege As Boolean = False
            Try
                'Set privileges for this application for rebooting pc.
                If PowerManager.SetPrivilege(PowerManagementNativeMethods.SEShutdownName) Then
                    If force Then
                        'Force all applications to close and reboot the system .
                        rebootComputerStatus = PowerManagementNativeMethods.ExitWindowsEx((PowerManagementNativeMethods.ExitWindowReboot + PowerManagementNativeMethods.ExitWindowForceIfHung + PowerManagementNativeMethods.ExitWindowForce), (PowerManagementNativeMethods.ShutdownReasonMajorApplication Or PowerManagementNativeMethods.ShutdownReasonMinorMaintenance))
                    Else
                        'Sends message to processes and it forces processes to terminate
                        'if they do not respond to the message within the timeout interval.
                        rebootComputerStatus = PowerManagementNativeMethods.ExitWindowsEx(PowerManagementNativeMethods.ExitWindowReboot, (PowerManagementNativeMethods.ShutdownReasonMajorApplication Or PowerManagementNativeMethods.ShutdownReasonMinorMaintenance))
                    End If
                    hasPrivilege = True
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not hasPrivilege Then
                Throw New PowerManagerException(PowerManagementResource.NoShutdownPrivilege)
            ElseIf Not rebootComputerStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                                                       + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return rebootComputerStatus
        End Function
        ''' <summary>
        ''' Shuts down the system and then restarts the system.
        ''' </summary>
        ''' <param name="rebootMessage">The message to be displayed in the 
        ''' shutdown dialog box.Maximum length is 511 characters.</param>
        ''' <param name="secondsTimer">The length of time that the shutdown
        ''' dialog box should be displayed, in seconds.MAX Shutdown TimeOut == 10 Years in seconds. 
        ''' ((10*365*24*60*60)-1 seconds).
        ''' </param>
        ''' <param name="force">If this parameter is TRUE, applications with 
        ''' unsaved changes are to be forcibly closed. Note that this can result 
        ''' in data loss.</param>
        ''' <returns>True, if reboot has been initiated.</returns>
        ''' <exception cref="ArgumentException">
        ''' The specified parameter is not valid.
        ''' </exception>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function RebootComputer(ByVal rebootMessage As String, ByVal secondsTimer As UInt32, ByVal force As Boolean) As Boolean
            'Check for valid parameter values.
            If Not [String].IsNullOrEmpty(rebootMessage) Then
                If rebootMessage.Length >= PowerManagementNativeMethods.MaximumMessageLength Then
                    Throw New ArgumentException(PowerManagementResource.RebootMessageLength)
                End If
            End If
            If secondsTimer >= PowerManagementNativeMethods.MaximumTimerValue Then
                Throw New ArgumentException(PowerManagementResource.MaximumRebootTimerValue)
            End If
            Dim rebootComputerStatus As Boolean = False
            Dim hasPrivilege As Boolean = False
            Try
                'Set privileges for this application for rebooting pc.
                If PowerManager.SetPrivilege(PowerManagementNativeMethods.SEShutdownName) Then
                    'Show specified message and reboot PC after specified time.
                    rebootComputerStatus = PowerManagementNativeMethods.InitiateSystemShutdown(Nothing, rebootMessage, secondsTimer, force, True)
                    hasPrivilege = True
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not hasPrivilege Then
                Throw New PowerManagerException(PowerManagementResource.NoShutdownPrivilege)
            ElseIf Not rebootComputerStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                                                       + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return rebootComputerStatus
        End Function
#End Region
#Region "ShutDown"
        ''' <summary>
        ''' Shuts down the system to a point at which it is safe to turn off 
        ''' the power.
        ''' </summary>
        ''' <param name="force">If True, then it forces processes to terminate. 
        ''' If false then sends message to processes and it forces processes 
        ''' to terminate if they do not respond to the message within the 
        ''' timeout interval.</param>
        ''' <returns>True, if shutdown has been initiated.</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function ShutdownComputer(ByVal force As Boolean) As Boolean
            Dim shutdownComputerStatus As Boolean = False
            Dim hasPrivilege As Boolean = False
            Try
                'Check whether the computer supports the soft off power state and 
                'Set privileges for this application for rebooting pc.
                If Me.IsPowerShutdownAllowed AndAlso PowerManager.SetPrivilege(PowerManagementNativeMethods.SEShutdownName) Then
                    If force Then
                        'Force all applications to close and shutdown the system.
                        shutdownComputerStatus = PowerManagementNativeMethods.ExitWindowsEx((PowerManagementNativeMethods.ExitWindowShutdown + PowerManagementNativeMethods.ExitWindowForceIfHung + PowerManagementNativeMethods.ExitWindowForce), (PowerManagementNativeMethods.ShutdownReasonMajorApplication Or PowerManagementNativeMethods.ShutdownReasonMinorMaintenance))
                    Else
                        'Sends message to processes and it forces processes to terminate
                        'if they do not respond to the message within the timeout interval.
                        shutdownComputerStatus = PowerManagementNativeMethods.ExitWindowsEx(PowerManagementNativeMethods.ExitWindowShutdown, (PowerManagementNativeMethods.ShutdownReasonMajorApplication Or PowerManagementNativeMethods.ShutdownReasonMinorMaintenance))
                    End If
                    hasPrivilege = True
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not hasPrivilege Then
                Throw New PowerManagerException(PowerManagementResource.NoShutdownPrivilege)
            ElseIf Not shutdownComputerStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                                                       + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return shutdownComputerStatus
        End Function
        ''' <summary>
        ''' Shuts down the system to a point at which it is safe to turn off 
        ''' the power.
        ''' </summary>
        ''' <param name="shutdownMessage">The message to be displayed 
        ''' in the shutdown dialog box.Maximum length is 511 characters..</param>
        ''' <param name="secondsTimer">The length of time that the shutdown 
        ''' dialog box should be displayed, in seconds.
        ''' MAX Shutdown TimeOut == 10 Years in seconds (((10*365*24*60*60)-1 seconds). </param>
        ''' <param name="force">If this parameter is TRUE, applications 
        ''' with unsaved changes are to be forcibly closed.
        ''' Note that this can result in data loss.
        ''' </param>
        ''' <returns>True, if shutdown has been initiated.</returns>
        ''' <exception cref="ArgumentException">
        ''' The specified parameter is not valid.
        ''' </exception>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function ShutdownComputer(ByVal shutdownMessage As String, ByVal secondsTimer As UInt32, ByVal force As Boolean) As Boolean
            'Check for valid parameter values.
            If Not [String].IsNullOrEmpty(shutdownMessage) Then
                If shutdownMessage.Length >= PowerManagementNativeMethods.MaximumMessageLength Then
                    Throw New ArgumentException(PowerManagementResource.ShutdownMessageLength)
                End If
            End If
            If secondsTimer >= PowerManagementNativeMethods.MaximumTimerValue Then
                Throw New ArgumentException(PowerManagementResource.MaximumShutdownTimerValue)
            End If
            Dim shutdownComputerStatus As Boolean = False
            Dim hasPrivilege As Boolean = False
            Try
                'Determines whether the computer supports the soft off power 
                'state and set privileges for this application for rebooting pc.
                If Me.IsPowerShutdownAllowed AndAlso PowerManager.SetPrivilege(PowerManagementNativeMethods.SEShutdownName) Then
                    'Show specified message and shutdown PC after specified time.
                    shutdownComputerStatus = (PowerManagementNativeMethods.InitiateSystemShutdown(Nothing, shutdownMessage, secondsTimer, force, False) <> False)
                    hasPrivilege = True
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not hasPrivilege Then
                Throw New PowerManagerException(PowerManagementResource.NoShutdownPrivilege)
            ElseIf Not shutdownComputerStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                                           + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return shutdownComputerStatus
        End Function
#End Region
        ''' <summary>
        ''' Shuts down the system and turns off the power. 
        ''' The system must support the power-off feature.
        ''' </summary>
        ''' <param name="force">If True, then it forces processes to terminate.
        ''' If false then sends message to processes and it forces processes 
        ''' to terminate if they do not respond to the message within 
        ''' the timeout interval.</param>
        ''' <returns>True, if the shutdown has been initiated</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function PowerOffComputer(ByVal force As Boolean) As Boolean
            Dim powerOffComputerStatus As Boolean = False
            Dim hasPrivilege As Boolean = False
            Try
                'Check whether the computer supports the soft off 
                'power state and set privileges for this application for rebooting pc.
                If Me.IsPowerShutdownAllowed AndAlso PowerManager.SetPrivilege(PowerManagementNativeMethods.SEShutdownName) Then
                    If force Then
                        'Force all applications to close and poweroff the system. 
                        powerOffComputerStatus = PowerManagementNativeMethods.ExitWindowsEx((PowerManagementNativeMethods.ExitWindowPowerOff + PowerManagementNativeMethods.ExitWindowForceIfHung + PowerManagementNativeMethods.ExitWindowForce), (PowerManagementNativeMethods.ShutdownReasonMajorApplication Or PowerManagementNativeMethods.ShutdownReasonMinorMaintenance))
                    Else
                        'Sends message to processes and it forces processes to terminate
                        ' if they do not respond to the message within the timeout interval.
                        powerOffComputerStatus = PowerManagementNativeMethods.ExitWindowsEx(PowerManagementNativeMethods.ExitWindowPowerOff, (PowerManagementNativeMethods.ShutdownReasonMajorApplication Or PowerManagementNativeMethods.ShutdownReasonMinorMaintenance))
                    End If
                    hasPrivilege = True
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not hasPrivilege Then
                Throw New PowerManagerException(PowerManagementResource.NoShutdownPrivilege)
            ElseIf Not powerOffComputerStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                                           + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return powerOffComputerStatus
        End Function
        ''' <summary>
        ''' Locks the workstation's display.This simulates the pressing of Windows+L key combination.
        ''' </summary>
        ''' <returns>True, if the Locking process has been initiated.</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function LockWorkStation() As Boolean
            Dim lockWorkStationStatus As Boolean = False
            Try
                'Lock workstation
                If PowerManagementNativeMethods.LockWorkstation() Then
                    lockWorkStationStatus = True
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not lockWorkStationStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                                           + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return lockWorkStationStatus
        End Function
        ''' <summary>
        ''' Hibernates the system.
        ''' </summary>
        ''' <param name="force">If this parameter is TRUE,the system suspends 
        ''' operation immediately; 
        ''' if it is FALSE, the system broadcasts an event to each application 
        ''' to request permission to suspend operation.</param>
        ''' <returns>True, if the function succeeds.</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        ''' <exception cref="InvalidOperationException">
        ''' This exception is raised if the computer does 
        ''' not support hibernation (power state S4) and 
        ''' the file Hiberfil.sys is not present on the system.
        ''' </exception>
        Public Function HibernateComputer(ByVal force As Boolean) As Boolean
            Dim hibernateComputerStatus As Boolean = False
            'Check whether the computer supports hibernation.
            If Me.IsPowerHibernateAllowed Then
                Throw New InvalidOperationException(PowerManagementResource.NoHibernationSupport)
            End If
            Try
                'Hibernates PC.
                hibernateComputerStatus = PowerManagementNativeMethods.SetSuspendState(True, force, False)
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not hibernateComputerStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                                           + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return hibernateComputerStatus
        End Function
        ''' <summary>
        ''' Hibernates the system.
        ''' </summary>
        ''' <returns>On successful execution returns true and the 
        ''' system broadcasts an event to each application to request
        ''' permission to suspend operation.
        ''' </returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        ''' <exception cref="InvalidOperationException">
        ''' This exception is raised if the computer does 
        ''' not support hibernation (power state S4) and 
        ''' the file Hiberfil.sys is not present on the system.
        ''' </exception>
        Public Function HibernateComputer() As Boolean
            Return Me.HibernateComputer(False)
        End Function
        ''' <summary>
        ''' Puts the system into suspend (sleep) state.
        ''' </summary>
        ''' <param name="force">If this parameter is TRUE, the system suspends 
        ''' operation immediately; if it is FALSE, the system broadcasts an 
        ''' event to each application to request permission to suspend 
        ''' operation.
        ''' </param>
        ''' <param name="disableWakeEvents">If this parameter is TRUE, 
        ''' the system disables all wake events. If the parameter is FALSE, 
        ''' any system wake events remain enabled.</param>
        ''' <returns>True, if the function succeeds.</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function StandbyComputer(ByVal force As Boolean, ByVal disableWakeEvents As Boolean) As Boolean
            Dim standbyComputerStatus As Boolean = False
            Try
                'Check whether the computer supports the sleep states.
                If Me.IsPowerSuspendAllowed Then
                    'Standby PC
                    standbyComputerStatus = PowerManagementNativeMethods.SetSuspendState(False, force, disableWakeEvents)
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not standbyComputerStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                                           + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return standbyComputerStatus
        End Function
        ''' <summary>
        ''' Logs off the current user.
        ''' </summary>
        ''' <param name="force">If True, then it forces processes to terminate.
        ''' If false then sends message to processes and it forces processes to 
        ''' terminate if they do not respond to the message within the timeout 
        ''' interval.</param>
        ''' <returns>True, if log off has been initiated.</returns>
        ''' <exception cref="PowerManagerException">
        ''' Call to native API has raised an error.
        ''' </exception>
        Public Function LogOffCurrentUser(ByVal force As Boolean) As Boolean
            Dim logOffCurrentUserStatus As Boolean = False
            Try
                If force Then
                    'Forces processes to terminate and Logoff current user.
                    logOffCurrentUserStatus = PowerManagementNativeMethods.ExitWindowsEx(PowerManagementNativeMethods.ExitWindowForce, 0)
                Else
                    'Sends message to processes and  forces processes to terminate
                    'if they do not respond to the message within the timeout interval 
                    'and logoff current user.
                    logOffCurrentUserStatus = PowerManagementNativeMethods.ExitWindowsEx(PowerManagementNativeMethods.ExitWindowLogOff, 0)
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            End Try
            If Not logOffCurrentUserStatus Then
                Throw New PowerManagerException(CType(PowerManagementResource.Win32ErrorCodeMessage, String) _
                                               + CType(Marshal.GetLastWin32Error(), String))
            End If
            Return logOffCurrentUserStatus
        End Function
#End Region
#End Region
#Region "Private Methods"
        ''' <summary>
        ''' Retrieves the active power scheme and returns a GUID that 
        ''' identifies the scheme.
        ''' </summary>
        ''' <returns>If the method succeeds then returns GUID of the 
        ''' active power scheme else it returns null.</returns>
        Private Shared Function GetActivePowerSchemeGuid() As String
            Dim ptrToActivePowerScheme As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
            'Get guid of active power scheme
            If Not PowerManagementNativeMethods.PowerGetActiveScheme(IntPtr.Zero, ptrToActivePowerScheme) Then
                Dim guidActiveScheme As Guid = DirectCast(Marshal.PtrToStructure(ptrToActivePowerScheme, GetType(Guid)), Guid)
                Marshal.FreeHGlobal(ptrToActivePowerScheme)
                Return guidActiveScheme.ToString()
            End If
            Marshal.FreeHGlobal(ptrToActivePowerScheme)
            Return Nothing
        End Function
        ''' <summary>
        ''' Sets the active power scheme for the current user.
        ''' </summary>
        ''' <param name="guid">Guid of the power scheme to activate.</param>
        ''' <returns>True, if the method succeeds.</returns>
        Private Shared Function SetActivePowerSchemeGuid(ByVal guid As String) As Boolean
            Dim ptrToActiveScheme As IntPtr = IntPtr.Zero
            Try
                Dim activeSchemeGuid As Guid = New Guid(guid)
                ptrToActiveScheme = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                Marshal.StructureToPtr(activeSchemeGuid, ptrToActiveScheme, True)
                'Set active power scheme
                If Not PowerManagementNativeMethods.PowerSetActiveScheme(IntPtr.Zero, ptrToActiveScheme) Then
                    Return True
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message)
            Finally
                Marshal.FreeHGlobal(ptrToActiveScheme)
            End Try
            Return False
        End Function
        ''' <summary>
        ''' Sets the application privileges.
        ''' </summary>
        ''' <param name="privilege">Privilege to be given to the current application.</param>
        ''' <returns>True, if the method succeeds.</returns>
        Private Shared Function SetPrivilege(ByVal privilege As String) As Boolean
            Dim success As Boolean
            Dim tokenPrivileges As TokenPrivileges
            Dim tokenHandle As IntPtr = IntPtr.Zero
            'Get handle to current process.
            Dim currentProcessHandle As IntPtr = PowerManagementNativeMethods.GetCurrentProcess()
            ' Get a token for this process. 
            success = PowerManagementNativeMethods.OpenProcessToken(currentProcessHandle, (PowerManagementNativeMethods.TokenAdjustPrivileges Or PowerManagementNativeMethods.TokenQuery), tokenHandle)
            'Set properties of token.
            tokenPrivileges.Count = 1
            tokenPrivileges.Luid = 0
            tokenPrivileges.Attribute = PowerManagementNativeMethods.SEPrivilegeEnabled
            'Get the LUID for specified privilege name.
            success = PowerManagementNativeMethods.LookupPrivilegeValue(Nothing, privilege, tokenPrivileges.Luid)
            'Enable specified privilege in the specified access token.
            success = PowerManagementNativeMethods.AdjustTokenPrivileges(tokenHandle, False, tokenPrivileges, 0, IntPtr.Zero, IntPtr.Zero)
            Return success
        End Function
        ''' <summary>
        ''' Retrieves the title and guid of the currently present 
        ''' power schemes.
        ''' </summary>
        ''' <returns>ArrayList containing the title and Guid of the 
        ''' power schemes.
        ''' </returns>
        Private Shared Function GetAvailablePowerSchemesAndGuid() As ArrayList
            Dim allSchemesAndGuid As ArrayList = New ArrayList()
            Dim ptrToPowerScheme As IntPtr = IntPtr.Zero
            Dim friendlyName As IntPtr = IntPtr.Zero
            Try
                Dim buffSize As UInteger = 100
                Dim schemeIndex As UInteger = 0
                ptrToPowerScheme = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                'Get the guids of all available power schemes.
                While PowerManagementNativeMethods.PowerEnumerate(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, PowerManagementNativeMethods.PowerDataAccessor.AccessScheme, schemeIndex, ptrToPowerScheme, _
                 buffSize) = 0
                    friendlyName = Marshal.AllocHGlobal(1000)
                    Dim schemeGuidStr As Guid = DirectCast(Marshal.PtrToStructure(ptrToPowerScheme, GetType(Guid)), Guid)
                    Dim schemeGuid As String = schemeGuidStr.ToString()
                    buffSize = 1000
                    'Pass the guid retrieved in PowerEnumerate as parameter 
                    'to get the power scheme name.
                    PowerManagementNativeMethods.PowerReadFriendlyName(IntPtr.Zero, ptrToPowerScheme, IntPtr.Zero, IntPtr.Zero, friendlyName, buffSize)
                    Dim schemeName As String = Marshal.PtrToStringUni(friendlyName)
                    allSchemesAndGuid.Add(New ArrayList())
                    'Add retrieved power scheme name in the arraylist
                    DirectCast(allSchemesAndGuid(CType(schemeIndex, Integer)), ArrayList).Add(schemeGuid)
                    'Add retrieved power scheme Guid in the arraylist
                    DirectCast(allSchemesAndGuid(CType(schemeIndex, Integer)), ArrayList).Add(schemeName)
                    schemeIndex += CType(1, UInteger)
                End While
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            Finally
                Marshal.FreeHGlobal(ptrToPowerScheme)
                Marshal.FreeHGlobal(friendlyName)
            End Try
            Return allSchemesAndGuid
        End Function
#Region "AC/DC methods"
        ''' <summary>
        ''' This method retrieves the AC/DC power setting values for the 
        ''' specified power scheme.
        ''' </summary>
        ''' <param name="powerSchemeTitle">Name of the power scheme.</param>
        ''' <param name="type">Type of the settings to be retrieved 
        ''' (Possible values are AC and DC).</param>
        ''' <returns>Power setting values.</returns>
        Private Shared Function ReadPowerSchemeValue(ByVal powerSchemeTitle As String, ByVal type As ValueType) As PowerScheme
            If [String].IsNullOrEmpty(powerSchemeTitle) Then
                Throw New ArgumentNullException("powerSchemeTitle")
            End If
            Dim allSchemes As ArrayList = PowerManager.GetAvailablePowerSchemesAndGuid()
            Dim flagFound As Boolean = False
            Dim index As Integer = 0
            For index = 0 To allSchemes.Count - 1
                'Check whether specified power scheme is present
                If (DirectCast(allSchemes(index), ArrayList))(1).ToString() = powerSchemeTitle Then
                    flagFound = True
                    Exit For
                End If
            Next
            If flagFound = False Then
                'Throw exception if specified power scheme does not exist
                Throw New ArgumentException(PowerManagementResource.PowerSchemeNotFound)
            End If
            Dim powerScheme As PowerScheme = New PowerScheme()
            powerScheme.Name = (DirectCast(allSchemes(index), ArrayList))(1).ToString()
            powerScheme.Guid = (DirectCast(allSchemes(index), ArrayList))(0).ToString()
            powerScheme.Description = GetDescription(powerScheme.Guid, Nothing, Nothing)
            'Get Sub Group details
            powerScheme.SubGroups.AddRange(PowerManager.GetSubGroups(powerScheme.Guid))
            For i As Integer = 0 To powerScheme.SubGroups.Count - 1
                powerScheme.SubGroups(i).PowerSettings.AddRange(PowerManager.GetPowerSettings(powerScheme.Guid, powerScheme.SubGroups(i).Guid, type))
            Next
            Return powerScheme
        End Function
        ''' <summary>
        ''' Gets the information of power settings available under specifed sub group.
        ''' </summary>
        ''' <param name="powerSchemeGuid">Guid of the power scheme.</param>
        ''' <param name="subGroupGuid">Guid of the setting sub group.</param>
        ''' <param name="type">Type of the value to be retrieved (Possible values AC or DC).</param>
        ''' <returns></returns>
        Private Shared Function GetPowerSettings(ByVal powerSchemeGuid As String, ByVal subGroupGuid As String, ByVal type As ValueType) As List(Of PowerSetting)
            If [String].IsNullOrEmpty(powerSchemeGuid) OrElse [String].IsNullOrEmpty(subGroupGuid) Then
                Throw New ArgumentNullException([String].Format(CultureInfo.InvariantCulture, PowerManagementResource.ErrorSpecifyBothArguments, "powerSchemeGuid", "subGroupGuid"))
            End If
            If Not PowerManager.ValidateGuid(powerSchemeGuid) Then
                Throw New ArgumentException([String].Format(CultureInfo.InvariantCulture, PowerManagementResource.ErrorInvalidGuid, "powerSchemeGuid"))
            End If
            If Not PowerManager.ValidateGuid(subGroupGuid) Then
                Throw New ArgumentException([String].Format(CultureInfo.InvariantCulture, PowerManagementResource.ErrorInvalidGuid, "subGroupGuid"))
            End If
            Dim friendlyName As IntPtr = IntPtr.Zero
            Dim settingGuidPtr As IntPtr = IntPtr.Zero
            Dim subGroupGuidPtr As IntPtr = IntPtr.Zero
            Dim powerSchemeGuidPtr As IntPtr = IntPtr.Zero
            Try
                Dim powerSettings As List(Of PowerSetting) = New List(Of PowerSetting)()
                friendlyName = Marshal.AllocHGlobal(1000)
                settingGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                subGroupGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                powerSchemeGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                Dim bufferSize As UInteger = 1000
                Dim guid As Guid = New Guid(subGroupGuid)
                Marshal.StructureToPtr(guid, subGroupGuidPtr, True)
                guid = New Guid(powerSchemeGuid)
                Marshal.StructureToPtr(guid, powerSchemeGuidPtr, True)
                Dim schemeIndex As UInteger = 0
                'Enumerate settings
                While PowerManagementNativeMethods.PowerEnumerate(IntPtr.Zero, powerSchemeGuidPtr, subGroupGuidPtr, PowerManagementNativeMethods.PowerDataAccessor.AccessIndividualSetting, schemeIndex, settingGuidPtr, _
                 bufferSize) = 0
                    Dim settingGuidStr As Guid = DirectCast(Marshal.PtrToStructure(settingGuidPtr, GetType(Guid)), Guid)
                    Dim settingGuid As String = settingGuidStr.ToString()
                    bufferSize = 1000
                    'Get the power setting name.
                    PowerManagementNativeMethods.PowerReadFriendlyName(IntPtr.Zero, powerSchemeGuidPtr, subGroupGuidPtr, settingGuidPtr, friendlyName, bufferSize)
                    Dim settingName As String = Marshal.PtrToStringUni(friendlyName)
                    Dim setting As PowerSetting = New PowerSetting()
                    setting.Name = settingName
                    setting.Guid = settingGuid.ToString()
                    setting.Description = GetDescription(powerSchemeGuid, subGroupGuid, setting.Guid)
                    setting.Value = GetValue(powerSchemeGuid, subGroupGuid, setting.Guid, type)
                    powerSettings.Add(setting)
                    schemeIndex += CType(1, UInteger)
                End While
                Return powerSettings
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            Finally
                Marshal.FreeHGlobal(friendlyName)
                Marshal.FreeHGlobal(powerSchemeGuidPtr)
                Marshal.FreeHGlobal(subGroupGuidPtr)
                Marshal.FreeHGlobal(settingGuidPtr)
            End Try
        End Function
        ''' <summary>
        ''' Validate a Guid.
        ''' </summary>
        ''' <param name="guid">Guid to be validated.</param>
        ''' <returns>True, if guid is value else false.</returns>
        Private Shared Function ValidateGuid(ByVal guid As String) As Boolean
            If [String].IsNullOrEmpty(guid) Then
                Return False
            End If
            Dim isGuid As Regex = New Regex(PowerManagementResource.RegularExpressionGuid, RegexOptions.Compiled)
            If guid.StartsWith("{") <> guid.EndsWith("}") Then
                Return False
            End If
            If isGuid.IsMatch(guid) Then
                Return True
            End If
            Return False
        End Function
        ''' <summary>
        ''' Gets the information of sub groups available under specifed power scheme.
        ''' </summary>
        ''' <param name="powerSchemeGuid">Guid of the power scheme.</param>
        ''' <returns>List of sub groups.</returns>
        Private Shared Function GetSubGroups(ByVal powerSchemeGuid As String) As List(Of SettingSubGroup)
            If [String].IsNullOrEmpty(powerSchemeGuid) Then
                Throw New ArgumentNullException("powerSchemeGuid")
            End If
            If Not PowerManager.ValidateGuid(powerSchemeGuid) Then
                Throw New ArgumentException([String].Format(CultureInfo.InvariantCulture, PowerManagementResource.ErrorInvalidGuid, "powerSchemeGuid"))
            End If
            Dim subGroupGuidPtr As IntPtr = IntPtr.Zero
            Dim powerSchemeGuidPtr As IntPtr = IntPtr.Zero
            Dim friendlyName As IntPtr = IntPtr.Zero
            Try
                Dim subGroups As List(Of SettingSubGroup) = New List(Of SettingSubGroup)()
                Dim subGroupGuids As String() = {PowerManagementResource.SubgroupBatteryGuid, PowerManagementResource.SubgroupDiskGuid, PowerManagementResource.SubgroupDisplayGuid, PowerManagementResource.SubgroupMultimediaGuid, PowerManagementResource.SubgroupPciExpressGuid, PowerManagementResource.SubgroupPowerButtonGuid, _
                 PowerManagementResource.SubgroupProcessorGuid, PowerManagementResource.SubgroupSearchIndexingGuid, PowerManagementResource.SubgroupSleepGuid, PowerManagementResource.SubgroupUsbGuid, PowerManagementResource.SubgroupWirelessAdapterGuid}
                subGroupGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                powerSchemeGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                friendlyName = Marshal.AllocHGlobal(1000)
                Dim g As Guid = New Guid(powerSchemeGuid)
                Marshal.StructureToPtr(g, powerSchemeGuidPtr, True)
                'Enumerate sub groups
                For Each guid As String In subGroupGuids
                    Dim subGroupGuid As Guid = New Guid(guid)
                    Marshal.StructureToPtr(subGroupGuid, subGroupGuidPtr, True)
                    Dim buffSize As UInteger = 1000
                    'Get the setting sub group name.
                    PowerManagementNativeMethods.PowerReadFriendlyName(IntPtr.Zero, powerSchemeGuidPtr, subGroupGuidPtr, IntPtr.Zero, friendlyName, buffSize)
                    Dim subGroupName As String = Marshal.PtrToStringUni(friendlyName)
                    Dim subGroup As SettingSubGroup = New SettingSubGroup()
                    subGroup.Name = subGroupName
                    subGroup.Guid = subGroupGuid.ToString()
                    subGroup.Description = GetDescription(powerSchemeGuid, subGroup.Guid, Nothing)
                    subGroups.Add(subGroup)
                Next
                Return subGroups
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            Finally
                Marshal.FreeHGlobal(powerSchemeGuidPtr)
                Marshal.FreeHGlobal(subGroupGuidPtr)
                Marshal.FreeHGlobal(friendlyName)
            End Try
        End Function
        ''' <summary>
        ''' Gets the value of the specified power setting.
        ''' </summary>
        ''' <param name="powerSchemeGuid">Guid of the power scheme.</param>
        ''' <param name="subGroupGuid">Guid of the setting sub group.</param>
        ''' <param name="settingGuid">Guid of the power setting.</param>
        ''' <param name="valueType">Type of the value to be retrieved (Possible values AC or DC).</param>
        ''' <returns>Value of the specified power setting.</returns>
        Private Shared Function GetValue(ByVal powerSchemeGuid As String, ByVal subGroupGuid As String, ByVal settingGuid As String, ByVal valueType As ValueType) As String
            If [String].IsNullOrEmpty(powerSchemeGuid) Then
                Throw New ArgumentNullException("powerSchemeGuid")
            End If
            If [String].IsNullOrEmpty(powerSchemeGuid) Then
                Throw New ArgumentNullException("subGroupGuid")
            End If
            If [String].IsNullOrEmpty(powerSchemeGuid) Then
                Throw New ArgumentNullException("settingGuid")
            End If
            If Not PowerManager.ValidateGuid(powerSchemeGuid) Then
                Throw New ArgumentException([String].Format(CultureInfo.InvariantCulture, PowerManagementResource.ErrorInvalidGuid, "powerSchemeGuid"))
            End If
            If Not PowerManager.ValidateGuid(subGroupGuid) Then
                Throw New ArgumentException([String].Format(CultureInfo.InvariantCulture, PowerManagementResource.ErrorInvalidGuid, "subGroupGuid"))
            End If
            If Not PowerManager.ValidateGuid(settingGuid) Then
                Throw New ArgumentException([String].Format(CultureInfo.InvariantCulture, PowerManagementResource.ErrorInvalidGuid, "settingGuid"))
            End If
            Dim value As String = [String].Empty
            Dim returnCode As UInteger = 0
            Dim indexValue As UInteger = 0
            Dim powerSchemeGuidPtr As IntPtr = IntPtr.Zero
            Dim subGroupGuidPtr As IntPtr = IntPtr.Zero
            Dim settingGuidPtr As IntPtr = IntPtr.Zero
            Try
                powerSchemeGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                subGroupGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                settingGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                Dim guid As Guid = New Guid(powerSchemeGuid)
                Marshal.StructureToPtr(guid, powerSchemeGuidPtr, True)
                guid = New Guid(subGroupGuid)
                Marshal.StructureToPtr(guid, subGroupGuidPtr, True)
                guid = New Guid(settingGuid)
                Marshal.StructureToPtr(guid, settingGuidPtr, True)
                If valueType = valueType.AC Then
                    returnCode = PowerManagementNativeMethods.PowerReadACValueIndex(IntPtr.Zero, powerSchemeGuidPtr, subGroupGuidPtr, settingGuidPtr, indexValue)
                Else
                    returnCode = PowerManagementNativeMethods.PowerReadDCValueIndex(IntPtr.Zero, powerSchemeGuidPtr, subGroupGuidPtr, settingGuidPtr, indexValue)
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            Finally
                Marshal.FreeHGlobal(powerSchemeGuidPtr)
                Marshal.FreeHGlobal(subGroupGuidPtr)
                Marshal.FreeHGlobal(settingGuidPtr)
            End Try
            If returnCode <> 0 Then
                Throw New PowerManagerException(PowerManagementResource.Win32ErrorCodeMessage + returnCode.ToString(CultureInfo.InvariantCulture))
            End If
            value = PowerManager.GetValueString(settingGuid, indexValue)
            Return value
        End Function
        ''' <summary>
        ''' Converts the specified index value to its equivalent readable form.
        ''' </summary>
        ''' <param name="settingGuid">Guid of the power setting.</param>
        ''' <param name="value">Index value of the setting.</param>
        ''' <returns>Readable value in string format.</returns>
        Private Shared Function GetValueString(ByVal settingGuid As String, ByVal value As UInteger) As String
            Dim valueString As String = [String].Empty
            Dim pChoices As String() = {PowerManagementResource.PowerSchemePowerSaverTitle, PowerManagementResource.ChoiceAutomatic, PowerManagementResource.PowerSchemeHighPerformanceTitle}
            Dim searchChoices As String() = {PowerManagementResource.PowerSchemePowerSaverTitle, PowerManagementResource.PowerSchemeBalancedTitle, PowerManagementResource.PowerSchemeHighPerformanceTitle}
            Dim mmChoices As String() = {PowerManagementResource.ChoiceDoNothing, PowerManagementResource.ChoicePreventIdle, PowerManagementResource.ChoiceUseAwayMode}
            Dim pciChoices As String() = {PowerManagementResource.ChoiceNone, PowerManagementResource.ChoiceModeratePowerSaving, PowerManagementResource.ChoiceMaximumPowerSaving}
            Dim waChoices As String() = {PowerManagementResource.ChoiceMaximumPerformance, PowerManagementResource.ChoiceLowPowerSaving, PowerManagementResource.ChoiceMediumPowerSaving, PowerManagementResource.ChoiceMaximumPowerSaving}
            Select Case settingGuid
                Case PowerManagementNativeMethods.BatteryCriticalActionGuid, PowerManagementNativeMethods.BatteryLowActionGuid, PowerManagementNativeMethods.PowerButtonLidCloseActionGuid, PowerManagementNativeMethods.PowerButtonActionGuid, PowerManagementNativeMethods.PowerButtonSleepActionGuid
                    valueString = (CType(value, BatteryAction)).ToString()
                    Exit Select
                Case PowerManagementNativeMethods.PowerButtonStartMenuActionGuid
                    valueString = (CType((value + 1), BatteryAction)).ToString()
                    Exit Select
                Case PowerManagementNativeMethods.BatteryLowLevelGuid, PowerManagementNativeMethods.BatteryCriticalLevelGuid, PowerManagementNativeMethods.DisplayBrightnessGuid, PowerManagementNativeMethods.ProcessorMinimumStateGuid, PowerManagementNativeMethods.ProcessorMaximumStateGuid, PowerManagementNativeMethods.SleepRequiredIdlenessGuid
                    valueString = value.ToString(CultureInfo.InvariantCulture) + PowerManagementResource.PostfixPercentage
                    Exit Select
                Case PowerManagementNativeMethods.BatteryLowNotificationGuid, PowerManagementNativeMethods.DisplayAdaptiveGuid, PowerManagementNativeMethods.SleepAllowAwayGuid, PowerManagementNativeMethods.SleepAllowHybridSleepGuid, PowerManagementNativeMethods.SleepAllowStandByGuid, PowerManagementNativeMethods.SleepAllowPreventGuid, _
                 PowerManagementNativeMethods.UsbSelectiveSuspendGuid, PowerManagementNativeMethods.SleepAutoWakeGuid
                    If value = 1 Then
                        valueString = PowerManagementResource.ChoiceEnabled
                    Else
                        valueString = PowerManagementResource.ChoiceDisabled
                    End If
                    Exit Select
                Case PowerManagementNativeMethods.HardDiskOffAfterGuid, PowerManagementNativeMethods.DisplayOffAfterGuid, PowerManagementNativeMethods.SleepAfterGuid, PowerManagementNativeMethods.SleepHibernateAfter
                    If value = 0 Then
                        valueString = PowerManagementResource.ChoiceNever
                    Else
                        valueString = value.ToString(CultureInfo.InvariantCulture) + PowerManagementResource.PostfixSeconds
                    End If
                    Exit Select
                Case PowerManagementNativeMethods.MMWhenSharingGuid
                    If value < mmChoices.Length Then
                        valueString = mmChoices(CType(value, Integer))
                    End If
                    Exit Select
                Case PowerManagementNativeMethods.PciExpressPowerManagementGuid
                    If value < pciChoices.Length Then
                        valueString = pciChoices(CType(value / 2, Integer))
                    End If
                    Exit Select
                Case PowerManagementNativeMethods.ProcessorCStateSettingGuid
                    If value / 2 < pChoices.Length Then
                        valueString = pChoices(CType(value / 2, Integer))
                    End If
                    Exit Select
                Case PowerManagementNativeMethods.ProcessorPerfStateSettingGuid
                    If value / 2 < pChoices.Length Then
                        valueString = pChoices(CType(value / 2, Integer))
                    End If
                    If value Mod 2 = 0 Then
                        valueString += PowerManagementResource.PostfixAcSpecific
                    Else
                        valueString += PowerManagementResource.PostfixDcSpecific
                    End If
                    Exit Select
                Case PowerManagementNativeMethods.SearchPowerSavingModeGuid
                    If value < searchChoices.Length Then
                        valueString = searchChoices(CType(value, Integer))
                    End If
                    Exit Select
                Case PowerManagementNativeMethods.WirelessAdapterPowerModeGuid
                    If value < waChoices.Length Then
                        valueString = waChoices(CType(value, Integer))
                    End If
                    Exit Select
                Case Else
                    valueString = value.ToString(CultureInfo.InvariantCulture)
                    Exit Select
            End Select
            Return valueString
        End Function
        ''' <summary>
        ''' Gets the description of the specifed power scheme , setting sub group or setting.
        ''' </summary>
        ''' <param name="schemeGuid">Guid of the power scheme.</param>
        ''' <param name="subGroupGuid">Guid of the setting sub group.</param>
        ''' <param name="settingGuid">Guid of the power setting.</param>
        ''' <returns>Description of the specified power scheme , setting sub group or setting.</returns>
        Private Shared Function GetDescription(ByVal schemeGuid As String, ByVal subGroupGuid As String, ByVal settingGuid As String) As String
            Dim returnCode As UInteger = 0
            Dim bufferSize As UInteger = 1000
            Dim description As IntPtr = IntPtr.Zero
            Dim powerSchemeGuidPtr As IntPtr = IntPtr.Zero
            Dim subGroupGuidPtr As IntPtr = IntPtr.Zero
            Dim settingGuidPtr As IntPtr = IntPtr.Zero
            Try
                If [String].IsNullOrEmpty(schemeGuid) Then
                    Return Nothing
                End If
                Dim guid As Guid = New Guid()
                If Not [String].IsNullOrEmpty(schemeGuid) Then
                    powerSchemeGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                    guid = New Guid(schemeGuid)
                    Marshal.StructureToPtr(guid, powerSchemeGuidPtr, True)
                    If Not [String].IsNullOrEmpty(subGroupGuid) Then
                        guid = New Guid(subGroupGuid)
                        subGroupGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                        Marshal.StructureToPtr(guid, subGroupGuidPtr, True)
                        If Not [String].IsNullOrEmpty(settingGuid) Then
                            guid = New Guid(settingGuid)
                            settingGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Guid)))
                            Marshal.StructureToPtr(guid, settingGuidPtr, True)
                        End If
                    End If
                End If
                description = Marshal.AllocHGlobal(1000)
                returnCode = PowerManagementNativeMethods.PowerReadDescription(IntPtr.Zero, powerSchemeGuidPtr, subGroupGuidPtr, settingGuidPtr, description, bufferSize)
                If returnCode = 0 Then
                    If bufferSize > 0 Then
                        Return Marshal.PtrToStringUni(description)
                    Else
                        Return [String].Empty
                    End If
                End If
            Catch exception As Exception
                Throw New PowerManagerException(exception.Message, exception)
            Finally
                Marshal.FreeHGlobal(description)
                Marshal.FreeHGlobal(powerSchemeGuidPtr)
                Marshal.FreeHGlobal(subGroupGuidPtr)
                Marshal.FreeHGlobal(settingGuidPtr)
            End Try
            If returnCode <> 0 Then
                Throw New PowerManagerException(PowerManagementResource.Win32ErrorCodeMessage + returnCode.ToString(CultureInfo.InvariantCulture))
            End If
            Return [String].Empty
        End Function
#End Region
#End Region
#Region "Private Enumerations"
        ''' <summary>
        ''' Types of power setting values.
        ''' </summary>
        Private Enum ValueType
            ''' <summary>
            ''' Value for AC.
            ''' </summary>
            AC
            ''' <summary>
            ''' Value of DC.
            ''' </summary>
            DC
        End Enum
        ''' <summary>
        ''' Represents actions for battery power settings of power schemes.
        ''' </summary>
        Private Enum BatteryAction
            ''' <summary>
            ''' Do nothing.
            ''' </summary>
            DoNothing = 0
            ''' <summary>
            ''' Suspend the system.
            ''' </summary>
            Sleep = 1
            ''' <summary>
            ''' Hibernate the system.
            ''' </summary>
            Hibernate = 2
            ''' <summary>
            ''' Shut down the system.
            ''' </summary>
            Shutdown = 3
        End Enum
#End Region
    End Class
#End Region
    ''' <summary>
    ''' Represents the power setting values of a power scheme.
    ''' </summary>
    Public Class PowerScheme
#Region "Private Members"
        ''' <summary>
        ''' Friendly name of the power scheme.
        ''' </summary>
        Private m_name As String
        ''' <summary>
        ''' Description of the power scheme.
        ''' </summary>
        Private m_description As String
        ''' <summary>
        ''' Guid of the power scheme.
        ''' </summary>
        Private m_guid As String
        ''' <summary>
        ''' List of sub groups of power settings within the power scheme.
        ''' </summary>
        Private m_subGroups As List(Of SettingSubGroup) = New List(Of SettingSubGroup)()
#End Region
#Region "Public Properties"
        ''' <summary>
        ''' Friendly name of the power scheme.
        ''' </summary>
        Public Property Name() As String
            Get
                Return Me.m_name
            End Get
            Set(ByVal value As String)
                Me.m_name = value
            End Set
        End Property
        ''' <summary>
        ''' Description of the power scheme.
        ''' </summary>
        Public Property Description() As String
            Get
                Return Me.m_description
            End Get
            Set(ByVal value As String)
                Me.m_description = value
            End Set
        End Property
        ''' <summary>
        ''' Guid of the power scheme.
        ''' </summary>
        Public Property Guid() As String
            Get
                Return Me.m_guid
            End Get
            Set(ByVal value As String)
                Me.m_guid = value
            End Set
        End Property
        ''' <summary>
        ''' List of sub groups of power settings within the power scheme.
        ''' </summary>
        Public ReadOnly Property SubGroups() As List(Of SettingSubGroup)
            Get
                Return Me.m_subGroups
            End Get
        End Property
#End Region
    End Class
    ''' <summary>
    ''' Represents a power setting sub group of a power scheme.
    ''' </summary>
    Public Class SettingSubGroup
#Region "Private Members"
        ''' <summary>
        ''' Friendly name of the sub group.
        ''' </summary>
        Private m_name As String
        ''' <summary>
        ''' Description of the setting sub group.
        ''' </summary>
        Private m_description As String
        ''' <summary>
        ''' Guid of the setting sub group.
        ''' </summary>
        Private m_guid As String
        ''' <summary>
        ''' List of power settings within the sub group.
        ''' </summary>
        Private m_powerSettings As List(Of PowerSetting) = New List(Of PowerSetting)()
#End Region
#Region "Public Properties"
        ''' <summary>
        ''' Friendly name of the sub group.
        ''' </summary>
        Public Property Name() As String
            Get
                Return Me.m_name
            End Get
            Set(ByVal value As String)
                Me.m_name = value
            End Set
        End Property
        ''' <summary>
        ''' Description of the setting sub group.
        ''' </summary>
        Public Property Description() As String
            Get
                Return Me.m_description
            End Get
            Set(ByVal value As String)
                Me.m_description = value
            End Set
        End Property
        ''' <summary>
        ''' Guid of the setting sub group.
        ''' </summary>
        Public Property Guid() As String
            Get
                Return Me.m_guid
            End Get
            Set(ByVal value As String)
                Me.m_guid = value
            End Set
        End Property
        ''' <summary>
        ''' List of power settings within the sub group.
        ''' </summary>
        Public ReadOnly Property PowerSettings() As List(Of PowerSetting)
            Get
                Return Me.m_powerSettings
            End Get
        End Property
#End Region
    End Class
    ''' <summary>
    ''' Represents a power setting of a power scheme.
    ''' </summary>
    Public Class PowerSetting
#Region "Private Members"
        ''' <summary>
        ''' Friendly name of the power setting.
        ''' </summary>
        Private m_name As String
        ''' <summary>
        ''' Description of the power setting.
        ''' </summary>
        Private m_description As String
        ''' <summary>
        ''' Guid of the power setting.
        ''' </summary>
        Private m_guid As String
        ''' <summary>
        ''' Value of the power setting.
        ''' </summary>
        Private m_value As String
#End Region
#Region "Public Properties"
        ''' <summary>
        ''' Friendly name of the power setting.
        ''' </summary>
        Public Property Name() As String
            Get
                Return Me.m_name
            End Get
            Set(ByVal value As String)
                Me.m_name = value
            End Set
        End Property
        ''' <summary>
        ''' Description of the power setting.
        ''' </summary>
        Public Property Description() As String
            Get
                Return Me.m_description
            End Get
            Set(ByVal value As String)
                Me.m_description = value
            End Set
        End Property
        ''' <summary>
        ''' Guid of the power setting.
        ''' </summary>
        Public Property Guid() As String
            Get
                Return Me.m_guid
            End Get
            Set(ByVal value As String)
                Me.m_guid = value
            End Set
        End Property
        ''' <summary>
        ''' Value of the power setting.
        ''' </summary>
        Public Property Value() As String
            Get
                Return Me.m_value
            End Get
            Set(ByVal value As String)
                Me.m_value = value
            End Set
        End Property
#End Region
    End Class
End Namespace
